module diagnostics_mod

  use constants_mod
  use namelist_mod

  implicit none

contains

  subroutine diagnose_total_mass(q, total_mass)

    real(r8), intent(in) :: q(1-nhalo:nx+nhalo)
    real(r8), intent(out) :: total_mass
    integer i
    total_mass = 0.0_r8
    if (space_scheme == 'MCV') then
      do i = 2, nx, 2
        total_mass = total_mass + via_1d(q(i-1:i+1)) * dx
      end do
    else
      total_mass = sum(q(1:nx)) * dx
    end if

  end subroutine diagnose_total_mass

  real(r8) function via_1d(q) result(res)
    
    real(r8), dimension(1:3), intent(in) :: q

    res = (q(1) + 4.0_r8 * q(2) + q(3)) / 6.0_r8

  end function via_1d

end module diagnostics_mod